home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 9 / FM Towns Free Software Collection 9.iso / t_os / shell / tsbgex / src / tool / misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-16  |  479 b   |  32 lines

  1. #include <stdio.h>
  2.  
  3. pattern_search(fp, pat, size)
  4. FILE *fp;
  5. char *pat;
  6. int size;
  7. {
  8.     char *s, ch;
  9.     int n, pos, off;
  10.  
  11.     pos = ftell(fp);
  12.     ch = fgetc(fp);    
  13.     do {
  14.         s = pat;
  15.         while (!feof(fp)  &&  ch != *s)
  16.             ch = fgetc(fp);
  17.         if (ch != *s)
  18.             break;
  19.         n = size - 1;
  20.         while (--n >= 0){
  21.             ch = fgetc(fp);
  22.             if (ch != *++s)
  23.                 break;
  24.         }
  25.     } while (n >= 0);
  26.     if (feof(fp))
  27.         return (-1);
  28.     off = ftell(fp) - size;
  29.     fseek(fp, pos, 0);
  30.     return (off);
  31. }
  32.